/*
 * ebc_route.c - EBC - routing
 * Clunix, KyungWoon Cho, cezanne@clunix.com, 2006.7
 *
 * Copyright (c) 2001-2008 by Clunix Inc. All Rights Reserved.
 */

#include "config.h"

#include "ebc_p.h"

ebc_err_t
ctl_route(ebc_t *ec, const char *pattern, const char *addrspec)
{
	sr_t	*sr_arg;
	ebc_err_t	err;

	sr_arg = sr_create_str(ST_STR, addrspec);
	if ((err = ebc_call_ebcd(ec, pattern, &sr_arg)) != EBC_OK) {
		sr_free(sr_arg);
		return err;
	}
	err = sr_get_int(sr_arg);
	sr_free(sr_arg);
	return err;
}

ebc_err_t
ebc_route_add(ecm_ebc_t ecm_ebc, const char *addrspec)
{
	return ctl_route(ecm_ebc, "routeadd", addrspec);
}

ebc_err_t
ebc_route_del(ecm_ebc_t ecm_ebc, const char *addrspec)
{
	return ctl_route(ecm_ebc, "routedel", addrspec);
}

ebc_err_t
ebc_route_get(ecm_ebc_t ecm_ebc, sr_t **psr_route_info)
{
	sr_t	*sr_arg;
	ebc_err_t	err;

	sr_arg = NULL;
	if ((err = ebc_call_ebcd(ecm_ebc, "routeget", &sr_arg)) != EBC_OK)
		return err;
	if (psr_route_info)
		*psr_route_info = sr_arg;
	else
		sr_free(sr_arg);
	return EBC_OK;
}
